package isPrefixOfWord;

public class Solution {
    public int isPrefixOfWord(String sentence, String searchWord) {
        //
        int index = 1;
        int i = 0,j = 0;
        while (j<sentence.length()){
            if(!check(j,sentence)){
                j++;
            } else {
                if(sentence.substring(i,j+1).startsWith(searchWord)) return index;
                j += 2;
                i = j;
                index++;
            }
        }
        return -1;
    }
    private boolean check(int i,String s) {
        if(i == s.length()-1) return true;
        return s.charAt(i)!=' '&&s.charAt(i+1)==' ';
    }
}
